package com.fudan.backend.controller;

import com.fudan.backend.exception.RetCode;
import com.fudan.backend.pojo.CommodityModifyRequest;
import com.fudan.backend.service.CommodityModifyRequestService;
import com.fudan.backend.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/commodity")
public class CommodityModifyRequestController {
    @Autowired
    CommodityModifyRequestService commodityModifyRequestService;

    @PostMapping("/modify-request")
    public R addCommodityModifyRequest(@RequestBody CommodityModifyRequest commodityModifyRequest){
        RetCode retCode = commodityModifyRequestService.addCommodityModifyRequest(commodityModifyRequest);
        return new R(retCode);
    }

    @PostMapping("/modify-request/process")
    public R processCommodityModifyRequest(@RequestBody CommodityModifyRequest commodityModifyRequest){
        RetCode retCode = commodityModifyRequestService.processCommodityModifyRequest(commodityModifyRequest);
        return new R(retCode);
    }

    @GetMapping("/modify-request")
    public R getAllCommodityModifyRequest(int current, int size){
        PageInfo<CommodityModifyRequest> page = commodityModifyRequestService.getAllCommodityModifyRequest(current, size);
        HashMap<String, Object> map = new HashMap<>();
        map.put("modifyRequestList", page.getList());
        map.put("total", page.getTotal());
        return new R(RetCode.COMMODITY_SUCCESS,map);
    }

    @GetMapping("/modify-request/store/{storeId}")
    public R getAllCommodityModifyRequestByStoreId(int current, int size,@PathVariable("storeId") String storeId){
        PageInfo<CommodityModifyRequest> page = commodityModifyRequestService.getAllCommodityModifyRequestByStoreId(current, size, storeId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("modifyRequestList", page.getList());
        map.put("total", page.getTotal());
        return new R(RetCode.COMMODITY_SUCCESS,map);
    }
}
